<template>
  <view>
    <picker mode="date" :value="date" :start="startDate" :end="endDate" @change="bindDateChange">
      <view class="picker">{{date}}</view>
    </picker>
    <button @click="submit">提交</button>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        date: this.getDate(),
        startDate: this.getDate('start'),
        endDate: this.getDate('end'),
      };
    },
    methods: {
      bindDateChange(e) {
        this.date = e.detail.value;
      },
      submit() {
        console.log(this.date);
      },
      getDate(type) {
        const date = new Date();
        let year = date.getFullYear();
        let month = date.getMonth() + 1;
        let day = date.getDate();
        if (type === 'start') {
          year = year - 60;
        } else if (type === 'end') {
          year = year + 2;
        }
        month = month > 9 ? month : '0' + month;
        day = day > 9 ? day : '0' + day;
        var res = year + "-" + month + "-" + day;
        return res;
      }
    }
  }
</script>

<style lang="scss">

</style>